package ai.mspbots.poc.controller.v2;

import ai.mspbots.poc.help.PocEnv;
import org.deeplearning4j.models.embeddings.loader.WordVectorSerializer;
import org.deeplearning4j.models.word2vec.Word2Vec;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;

@RestController
@RequestMapping("/v2/helper")
public class HelperController {

    @Autowired
    private PocEnv pocEnv;

    /**
     * 转换模型
     */
    @PostMapping("/word2vec")
    public String writeWord2VecModel() {
        Word2Vec wordVectors = WordVectorSerializer.readWord2VecModel(new File(pocEnv.getGlove().getText()));
        WordVectorSerializer.writeWord2VecModel(wordVectors, new File(pocEnv.getGlove().getModel()));
        return "success";
    }
}
